﻿using Microsoft.EntityFrameworkCore;
using System.Reflection;

namespace EF_coreDemo
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            using (DBContext db = new DBContext())
            {
                //插入
                /*
                Book book1 = new Book()
                {
                    Title = "Test1",
                    PubTime = DateTime.Now,
                    Price = 1,
                    AuthorName = "Test1",  
                };
                Book book2 = new Book()
                {
                    Title = "Test2",
                    PubTime = DateTime.Now,
                    Price = 100,
                    AuthorName = "Test2",
                };
                Book book3 = new Book()
                {
                    Title = "Test3",
                    PubTime = DateTime.Now,
                    Price = 1,
                    AuthorName = "Test3",
                };
                db.Books.Add(book1);
                db.Books.Add(book2);
                    db.Books.Add(book3);
                */

                //更新
                //var d1 = db.Books.Single(e => e.Title == "Test1");
                //d1.AuthorName = "yhd";

                //删除
                //var d2 = db.Books.Single(e => e.Title == "Test1");
                //db.Remove(d1);

                //查询
                //var d3 = db.Books.OrderBy(e => e.PubTime);
                //foreach (var d4 in d3)
                //{
                //    Console.WriteLine($"id={d4.Id},title={d4.Title}");
                //}

                var v1 = db.Books.Where(e => e.Id>0);
                var v2 = v1.ToQueryString();
                Console.WriteLine(v2);
                foreach (var item in v1)
                {
                    item.Price++;
                }


                await db.SaveChangesAsync();
            }
                
        }
    }
}
